import type {
  CodeType,
  User,
  CodeData,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'
import { request } from '@/utils/request'
// 登录 密码登录
export const loginByPassworld = (mobile: string, password: string) => {
  return request<User>('login/password', 'post', { mobile, password })
}
// 发送 短信验证码
export const sendMobileCode = (mobile: string, type: CodeType) => {
  return request<CodeData>('code', 'GET', { mobile, type })
}

// 登录 手机验证码登录
export const loginByCode = (mobile: string, code: string) => {
  return request<User>('login', 'post', { mobile, code })
}

// 获取用户信息
export const getUserInfo = () => request<UserInfo>('patient/myUser')

// 获取患者信息列表
export const getPatientList = () => request<PatientList>('patient/mylist')

// 添加患者信息
export const addPatient = (FromData: Patient) =>
  request<{ id: string }>('patient/add', 'post', FromData)

// 编辑患者信息
export const updatePatient = (FromData: Patient) =>
  request<{ id: string }>('patient/update', 'PUT', FromData)

// 删除患者信息
export const deletePatient = (id: string) =>
  request<{ id: string }>(`patient/del/${id}`, 'DELETE')

// 查询患者信息
export const getPatientDetail = (patientId: string) =>
  request<Patient>(`patient/info/${patientId}`, 'GET')

// QQ登录
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

// QQ登录绑定手机号
export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>('/login/binding', 'POST', data)
